from libs import northstar
import time
northstar.init_SCREEN()
northstar.init_BUTTON()
oled = northstar.oled
def showload(load): # 显示加载
    oled.fill(0)
    oled.rect(54, 34, 20, 20, 1)
    oled.rect(59, 39, 10, 10, 1)
    oled.rect(59, 39, 15, 1, 1)
    oled.fill_rect(60, 40, 14, 3, 0)
    if load<=25:
        load1=int((load-0)*(18/25))
        load2=0
        load3=0
        load4=0
    elif load<=50:
        load1=18
        load2=int((load-25)*(18/25))
        load3=0
        load4=0
    elif load<=75:
        load1=18
        load2=18
        load3=int((load-50)*(18/25))
        load4=0
    elif load<100:
        load1=18
        load2=18
        load3=18
        load4=int((load-75)*(10/25))
    else:
        load1=18
        load2=18
        load3=18
        load4=10
    oled.fill_rect(55+18-load1, 35, load1, 4, 1)
    oled.fill_rect(55, 35, 4, load2, 1)
    oled.fill_rect(55, 49, load3, 4, 1)
    oled.fill_rect(55+14, 49+4-load4, 4, load4, 1)
def showload2(load): # 反向加载，用于结尾
    showload(100)
    if load<=25:
        load1=int((load-0)*(18/25))
        load2=0
        load3=0
        load4=0
    elif load<=50:
        load1=18
        load2=int((load-25)*(18/25))
        load3=0
        load4=0
    elif load<=75:
        load1=18
        load2=18
        load3=int((load-50)*(18/25))
        load4=0
    elif load<100:
        load1=18
        load2=18
        load3=18
        load4=int((load-75)*(10/25))
    else:
        load1=18
        load2=18
        load3=18
        load4=10
    oled.fill_rect(55+18-load1, 35, load1, 4, 0)
    oled.fill_rect(55, 35, 4, load2, 0)
    oled.fill_rect(55, 49, load3, 4, 0)
    oled.fill_rect(55+14, 49+4-load4, 4, load4, 0)

def showload3(j): # 最后的分开效果
    oled.fill(0)
    
    oled.rect(54-j, 34, 20, 1, 1)
    oled.rect(54, 34+j, 1, 20, 1)
    oled.rect(54+j, 53, 20, 1, 1)
    oled.rect(73, 34-j, 1, 6, 1)
    oled.rect(73, 43+j, 1, 11, 1)
    
    oled.rect(59+j, 39, 15, 1, 1)
    oled.rect(59, 39-j, 1, 10, 1)
    oled.rect(59-j, 48, 10, 1, 1)
    oled.rect(68, 43+j, 1, 6, 1)
def finishload(): # 结束效果
    for i in range(0,101,3):
        showload2(i)
        oled.show()
    
    time.sleep(0.5)
    for i in range(0,10,2):
        showload3(i)
        oled.show()
    for i in range(11,40,5):
        showload3(i)
        oled.show()
    for i in range(41,60,4):
        showload3(i)
        oled.show()
    for i in range(61,80,2):
        showload3(i)
        oled.show()
    